function start(){

    var uid = document.getElementById("uid").value;
    var ws = new WebSocket('ws://127.0.0.1:1234');
    if(uid == ''){
        //检测用户是否设置了名称
        return ;
    }
    ws.onopen = function(){
        
        var uid = document.getElementById("uid").value;
        ws.send(uid);
    };
    ws.onmessage = function(e){
        var data  = eval("(" + e.data + ")");
        switch(data.msgType){
            case 0 :
                //推送用户列表
                setUserList(data.data);
             ;break;

            case 1 :

                ;break;

            default : 

                    var  html = document.getElementById("msgs").innerHTML;
                    html += '<li class="msg"><span class="from">'+data.uid+' 说：</span><div class="words"> '+data.message+'</div>' ;
                    document.getElementById("msgs").innerHTML = html;
                    console.log(e.data);
        }
        
    }

}


//设置用户列表
function setUserList(users){

    // <li> <span class="online">■</span>游云随风</li>
    var html = "";
    for(var i=0;i<users.length;i++){
        html += '<li> <span class="online">■</span>'+users[i]+'</li>';
    }

    document.getElementById("memberlist").innerHTML = html;

}